package com.zzc.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zzc.common.JsonResult;
import com.zzc.common.TableResult;
import com.zzc.mapper.CustomerMapper;
import com.zzc.pojo.Customer;
import com.zzc.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author zhouzhicheng
 * @version 1.0  2020/12/29
 */
@Service
public class CustomerServiceImpl implements CustomerService {
    @Autowired
    private CustomerMapper customerMapper;
    @Override
    public int deleteByPrimaryKey(Integer id) {
        return 0;
    }

    @Override
    public int insert(Customer record) {
        return 0;
    }

    @Override
    public JsonResult insertSelective(Customer record) {
        return customerMapper.insertSelective(record)>0? JsonResult.getResultSuccess():JsonResult.getResultFailed();
    }

    @Override
    public Customer selectByPrimaryKey(Integer id) {
        return null;
    }

    @Override
    public JsonResult updateByPrimaryKeySelective(Customer record) {
        return customerMapper.updateByPrimaryKeySelective(record)>0?JsonResult.getResultSuccess():JsonResult.getResultFailed();
    }

    @Override
    public int updateByPrimaryKeyWithBLOBs(Customer record) {
        return 0;
    }

    @Override
    public int updateByPrimaryKey(Customer record) {
        return 0;
    }

    @Override
    public TableResult getCustomer(Integer page,Integer limit,String name, Integer state) {
        //分页设置 当前页和每页大小
        PageHelper.startPage(page,limit);
        //获取分页信息
        PageInfo<Customer> pageInfo = new PageInfo<>(customerMapper.getCustomer(name,state));

        return new TableResult(0,null,Long.valueOf(pageInfo.getTotal()).intValue(),pageInfo.getList());
    }

    @Override
    public JsonResult deleteCustomersById(Integer[] ids) {
        return customerMapper.deleteById(ids)>0
                ? JsonResult.getResultSuccess()
            : JsonResult.getResultFailed();
    }

    @Override
    public List<Customer> getAllCustomer() {
        return customerMapper.getCustomer(null,null);
    }
}
